package org.carabiner.infinitest;

import org.carabiner.infinitest.swingui.InfinitestView;

public class Status
{
  public static final Status SCANNING = new Status("Scanning For Tests");
  public static final Status RUNNING = new Status("Running Test");
  public static final Status PASSING = new PassingStatus();
  public static final Status FAILING = new FailingStatus();
  public static final Status PAUSED = new PausedStatus();

  private final String desc;

  private Status(String description)
  {
    desc = description;
  }

  @Override
  public String toString()
  {
    return desc;
  }
  
  public void updateView(InfinitestView view)
  {
    view.setStatusName(desc);
  }
  
  private static class PassingStatus extends Status
  {
    private PassingStatus()
    {
      super("Waiting for changes");
    }
    
    @Override
    public void updateView(InfinitestView view)
    {
      super.updateView(view);
      view.setColor(InfinitestSettings.PASSING_COLOR);
      view.setProgress(view.getMaximumProgress());
    }
  }
  
  private static class FailingStatus extends Status
  {
    private FailingStatus()
    {
      super("Tests Failing");
    }
    
    @Override
    public void updateView(InfinitestView view)
    {
      super.updateView(view);
      view.setColor(InfinitestSettings.FAILURE_COLOR);
      view.setProgress(view.getMaximumProgress());
    }
  }
  
  private static class PausedStatus extends Status
  {
    private PausedStatus()
    {
      super("Tests Paused");
    }
    
    @Override
    public void updateView(InfinitestView view)
    {
      super.updateView(view);
      view.setColor(InfinitestSettings.UNKNOWN_COLOR);
      view.setProgress(0);
    }
  }
}
